package org.grpc.controller;

import cn.hutool.core.util.RandomUtil;
import lombok.extern.slf4j.Slf4j;
import org.grpc.annotation.Monitor;
import org.grpc.service.MonitorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * description:
 *
 * @author shun.chen
 * @date 2022/5/17
 */
@Slf4j
@RestController
@RequestMapping()
public class MonitorController {

    @Autowired
    private MonitorService monitorServiceImpl;

    //监控指标注解使⽤
//    @Tp(description = "/monitor/test")
//    @Count(description = "/monitor/test")
    @Monitor(description = "/monitor/test")
    @GetMapping("/test")
    public String monitorTest(@RequestParam("name") String name) {
        monitorServiceImpl.monitorTest(name);
        try {

            int a = RandomUtil.randomInt(100, 500);
            Thread.sleep(a);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        log.info("monitorTest input param : {}", name);
        return "监控⽰范⼯程测试接⼝返回->OK!" + name;
    }

    //监控指标注解使⽤
//    @Tp(description = "/monitor/test")
//    @Count(description = "/monitor/test")
    @Monitor(description = "/monitor/uat")
    @GetMapping("/uat")
    public String monitorUat(@RequestParam("name") String name) {
        monitorServiceImpl.monitorTest(name);
        try {
            int a = RandomUtil.randomInt(100, 500);
            Thread.sleep(a);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        log.info("monitorUat input param : {}", name);
        return "监控⽰范⼯程测试接⼝返回->OK!" + name;
    }

}
